/**
 * Project Name:lee
 * File Name:UserloginController.java
 * Package Name:com.lee.system.controller
 * Date:2017年1月5日上午10:46:27
 * Copyright (c) 2017, chenzhou1025@126.com All Rights Reserved.
 *
*/

package com.lee.system.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.lee.annotation.SystemLog;
import com.lee.base.controller.BaseController;
import com.lee.common.page.PageView;
import com.lee.common.utils.Common;
import com.lee.system.model.UserLogin;
import com.lee.system.service.UserLoginService;

/**
 * ClassName:UserloginController <br/>
 * Function: TODO ADD FUNCTION. <br/>
 * Reason:	 TODO ADD REASON. <br/>
 * Date:     2017年1月5日 上午10:46:27 <br/>
 * @author   dell
 * @version  
 * @since    JDK 1.6
 * @see 	 
 */
@Controller
@RequestMapping("/userlogin/")
public class UserloginController extends BaseController{
	@Autowired
	private UserLoginService userLoginService;
	
	@RequestMapping("intoUserloginList")
	public ModelAndView intoUserloginList(){
		ModelAndView mav = new ModelAndView("/system/userlogin/list");
		return mav;
	}
	
	@ResponseBody
	@RequestMapping("findByPage")
	public PageView findByPage(UserLogin userLogin, String pageNow,
			String pageSize,String column,String sort) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		map = toFormMap(pageNow, pageSize);
		map.put("column", column);
		map.put("sort", sort);
		map.put("userLogin", userLogin);
		List<UserLogin> list = userLoginService.findByPage(map);
		int count = userLoginService.count(userLogin);
		pageView.setRecords(list);
		pageView.setRowCount(count);
        return pageView;
	}
	
	@SystemLog(module="系统管理",methods="删除登录日志")
	@RequestMapping("del")
	@ResponseBody
	public String del(HttpServletRequest request,int id){
		String flag="false";
		int i = userLoginService.delete(id,true);
		if(i>0){
			flag = "true";
		}
		return flag;
	}
	//获取近五天的用户访问量
	@RequestMapping("getDay")
	@ResponseBody
	public Map<String,Object> getDay(int day){
		Map<String, Object> map = new HashMap<String, Object>();
		List<Integer> list = new ArrayList<Integer>();
		List<String> listDays =	Common.fromDateDayNow(day,true,true);
		for (String string : listDays) {
			UserLogin search = new UserLogin();
			search.setLogintime(string);
			int i = userLoginService.getCountByContent(search);
			list.add(i);
		}
		map.put("listDay", listDays);
		map.put("listData", list);
		return map;
	}
}

